<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
  <link rel="stylesheet" href="/static/js/layui/css/layui.css" media="all">
  <script type="text/javascript" src="/static/js/jquery/jquery-3.5.1.min.js"></script>
  <script type="text/javascript" src="/static/js/layui/layui.js"></script>
</head>
<body>
<div class="layui-tab layui-tab-brief">
  <div class="layui-col-md2 layui-col-md-offset1">
    <form class="layui-form" action="">
      <div class="layui-form-item">
        <label class="layui-form-label">商品名：</label>
        <div class="layui-input-block">
          <input type="text" name="title" id="name" style="width: 200px;" lay-verify="title" autocomplete="off" placeholder="请输入商品名" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label">价格：</label>
        <div class="layui-input-block">
          <input type="text" name="title" id="price" style="width: 200px;" lay-verify="title" autocomplete="off" placeholder="请输入价格" class="layui-input">
        </div>
      </div>
      <div style="width: 350px; text-align: center">
        <div class="layui-btn-container">
          <button type="button" id="btn" class="layui-btn layui-btn-lg layui-btn-radius layui-btn-normal">确认添加</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script>
  // layui.use(['form', 'layedit', 'laydate'], function(){
  //     var form = layui.form
  //         ,layer = layui.layer
  //         ,layedit = layui.layedit
  //         ,laydate = layui.laydate;
  // });
  $(function () {
    $("#btn").click(function(){
      if ($("#name").val()==''){
        layer.msg("请输入商品名");
        return;
      }
      if ($("#phone").val()==''){
        layer.msg("请输入价格");
        return;
      }
      var param = {"name":$("#name").val(),"price":$("#price").val()}
      console.log(param);
      $.ajax({
        url:"/main/manage/insert/lingjian",
        data:param,
        dataType:"json",
        success:function (data){
          // console.log(data);
          if (data==1){
            layer.msg("添加成功");
            setTimeout(function (){
              var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
              parent.layer.close(index);
            },1500);
          }else if (data==2){
            layer.msg("商品已存在");
          }else {
            layer.msg("发生什么事了！！");
          }
        }
      })
    });
    function renderForm() {
      layui.use('form', function () {
        var form = layui.form;
        form.render();
      });
      return;
    }
  });
</script>
</body>
</html>